package cn.gz.demo.ui.comment;


import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import cn.gz.demo.R;
import cn.gz.demo.databinding.EditBinding;
import cn.gz.demo.ui.base.BaseActivity;

/**
 * Created by Lyz on 2017/3/8.
 */
public class PingLunActivity extends BaseActivity {
    private EditBinding binding;
    private InputTextMsgDialog inputTextMsgDialog;
    private int offsetY;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_edit);

        binding.btn.setOnClickListener(v -> {
            initInputTextMsgDialog(null, false, -1);
        });
    }

    private void initInputTextMsgDialog(View view, final boolean isReply, final int position) {
        dismissInputDialog();
        if (view != null) {
            offsetY = view.getTop();
//            scrollLocation(offsetY);
        }
        if (inputTextMsgDialog == null) {
            inputTextMsgDialog = new InputTextMsgDialog(this, R.style.dialog_center);
            inputTextMsgDialog.setmOnTextSendListener(new InputTextMsgDialog.OnTextSendListener() {
                @Override
                public void onTextSend(String msg) {
                }

                @Override
                public void dismiss() {
                    //item滑动到原位
                    scrollLocation(-offsetY);
                }
            });
        }
        showInputTextMsgDialog();
    }

    private void dismissInputDialog() {
        if (inputTextMsgDialog != null) {
            if (inputTextMsgDialog.isShowing()) {
                inputTextMsgDialog.dismiss();
            }
            inputTextMsgDialog.cancel();
            inputTextMsgDialog = null;
        }
    }

    private void showInputTextMsgDialog() {
        inputTextMsgDialog.show();
    }

    // item滑动
    public void scrollLocation(int offsetY) {
//        try {
//            rv_dialog_lists.smoothScrollBy(0, offsetY);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }
}
